package com.auth.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.auth.common.result.Result;
import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:Tangjiachang
 * @Date 2023/7/16
 * @Description:
 */
public class ResponseUtils {
     public static void out(HttpServletResponse response, HttpServletRequest request, Result result) {
        ObjectMapper objectMapper = new ObjectMapper();
        response.setStatus(HttpStatus.OK.value());
        response.setContentType(StringPool.APPLICATION_JSON_VALUE);
        try {
            objectMapper.writeValue(response.getWriter(), result);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
